<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<!-- Casting SPELs in Lisp - Emacs Lisp Edition, a Comic Book
     Written by Conrad Barski, M.D., http://lisperati.com
     Edited by James A. Webb, http://uberkode.com -->

<head>

  <title>Casting SPELs in Lisp (27)</title>
  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="author" content="James A. Webb" />
  <meta name="date" content="2007-09-16T00:00:00+00:00" />
  <meta name="keywords" content="Emacs, Lisp" />

</head>

<body>

<center>

<table cellspacing="10" width="500">
  <tr>
    <td align="center">
      <img src="../images/game-action.jpg"
        width="500" 
        height="335" 
        alt="Showing the game-action command." />
    </td>
  </tr>
  <tr>
    <td>
      The point of this SPEL is to show you just how sophisticated
      and clever you can get with these SPELs. Also, the ugliness
      doesn't really matter much if we only have to write it once and
      then can use it to make hundreds of commands for a bigger
      adventure game.
    </td>
  </tr>
  <tr>
    <td>
      Let's use our new SPEL to replace our ugly <tt>weld</tt>
      command:
    </td>
  </tr>
  <tr>
    <td>
<pre style="font-weight: bolder; color: darkblue">
  (game-action weld chain bucket attic
    (cond ((and (have 'bucket) (setq chain-welded 't))
           '(the chain is now securely welded to the bucket -))
          (t '(you do not have a bucket -))))
</pre>
    </td>
  </tr>
  <tr>
    <td>
      Look at how much easier it is to understand this command -
      The <tt>game-action</tt> SPEL lets us write exactly what we
      want to say without a lot of fat. It's almost like we've
      created our own computer language just for creating game
      commands. Creating your own pseudo-language with SPELs is
      called <i>Domain Specific Language Programming</i>, a
      very powerful way to program quickly and elegantly.
    </td>
  </tr>
  <tr>
    <td>
<pre style="font-weight: bolder; color: darkblue">
  (weld chain bucket)
</pre>
    </td>
  </tr>
  <tr>
    <td>
<pre style="font-weight: bolder; color: darkgreen">
  ==> (you do not have the chain -)
</pre>
    </td>
  </tr>
  <tr>
    <td>
      ...we still aren't in the right situation to do any welding,
      but the command is doing its job!
    </td>
  </tr>
  <tr>
    <td align="center">
      &lt;&lt; <a href="casting-spels-emacs-1.html">begin</a>
      &lt; <a href="casting-spels-emacs-26.html">previous</a> - 
      <a href="casting-spels-emacs-28.html">next</a> &gt;
      <a href="casting-spels-emacs-35.html" >end</a> &gt;&gt;
    </td>
  </tr>
</table>

</center>

</body>

</html>